package com.byxy.ssm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.byxy.ssm.pojo.User;

public interface UserMapper {
	
    
	@Insert("insert into user(user_name,user_nick,user_password,user_status,user_type) values(#{userName},#{userNick},#{userPassword},#{userStatus},#{userType})")
    int insert(User user);
	
    
    @Select("select * from user where user_id=#{userId}")
    @Results(id="dataset",value={
    	@Result(id=true,column="user_id",property="userId"),
    	@Result(column="user_name",property="userName"),
    	@Result(column="user_nick",property="userNick"),
    	@Result(column="user_password",property="userPassword"),
    	@Result(column="user_status",property="userStatus"),
    	@Result(column="user_type",property="userType")
    })
    User getById(Integer userId);
    
    @ResultMap("dataset")
    @Select("select * from user where user_name=#{userName} and user_password=#{userPassword}")
    User getByLogin(User user);
    
    @ResultMap("dataset")
    @Select("select * from user")
    List<User> findAll();

    @Update("update user set user_nick=#{userNick},user_password=#{userPassword} where user_id=#{userId}")
    int update(User user);
    @Update("update user set user_status=#{userStatus} where user_id=#{userId}")
	int updateStatus(@Param("userId") Integer userId,@Param("userStatus") Integer userStatus);
}